package com.mvp.shq.washer.ui.paySuccess;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.mvp.shq.washer.R;
import com.mvp.shq.washer.base.BaseActivity;
import com.mvp.shq.washer.entity.OrderInfo;
import com.mvp.shq.washer.rxbus.RxBus;
import com.mvp.shq.washer.utils.EventCode;
import com.mvp.shq.washer.utils.SpUtil;
import com.mvp.shq.washer.utils.T;
import com.zhy.autolayout.AutoRelativeLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class PaySuccessActivity extends BaseActivity<Presenter, Model> implements PaySuccessConstract.View {

    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.tv_pay_money)
    TextView tvPayMoney;
    @BindView(R.id.tv_order_no)
    TextView tvOrderNo;
    @BindView(R.id.img_washer)
    ImageView imgWasher;
    @BindView(R.id.tv_washer_info)
    TextView tvWasherInfo;
    @BindView(R.id.tv_washer_no)
    TextView tvWasherNo;
    @BindView(R.id.tv_washer_address)
    TextView tvWasherAddress;
    @BindView(R.id.img_icon)
    ImageView imgIcon;
    @BindView(R.id.tv_pattern)
    TextView tvPattern;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.tv_money)
    TextView tvMoney;
    @BindView(R.id.arl_bg)
    AutoRelativeLayout arlBg;
    @BindView(R.id.tv_money_unit)
    TextView tvMoneyUnit;
    private String orderNo;

    @Override
    public int getLayoutId() {
        return R.layout.activity_pay_success;
    }

    @Override
    public void initView() {
        orderNo = this.getIntent().getExtras().getString("orderNo");
        title.setText("支付成功");
        showLoadingDialog(true);
        presenter.getOrderInfo(orderNo);
    }

    @OnClick(R.id.back)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void getOrderS(OrderInfo orderInfo) {
        if (orderInfo == null){
            T.show("获取订单信息失败");
            return;
        }
        SpUtil.setOrder(orderInfo);
        RxBus.get().send(EventCode.GET_STATUS_ORDER);
        tvOrderNo.setText("订单号:"+orderInfo.getOrderNo());
        tvWasherNo.setText("NO."+orderInfo.getWasherNo());
        tvWasherInfo.setText(orderInfo.getWasherBrand()+" "+orderInfo.getWasherSpecDes());
        tvWasherAddress.setText(orderInfo.getWasherAddress());
        tvPattern.setText(orderInfo.getPatternName());
        if ("3".equals(orderInfo.getPayType())){
            tvMoneyUnit.setVisibility(View.GONE);
            tvPayMoney.setText("优惠券");
        }else {
            tvMoneyUnit.setVisibility(View.VISIBLE);
            tvPayMoney.setText(orderInfo.getTotalMoney()+"");
        }
        tvMoney.setText("￥"+orderInfo.getPatternPrice());
        tvTime.setText(orderInfo.getPatternTime()+"min");
        imageUtil.loadResImage(R.mipmap.washing_machine,imgWasher);
    }

}
